﻿using BasecampRestAPI;
using NUnit.Framework;
using TestBasecampRestAPI.TestMoveToDoList;

namespace TestBasecampRestAPI
{
	[TestFixture]
	public class TestCompany
	{
		[Test]
		public void Construct()
		{
			FakeBaseCamp camp = FakeBaseCamp.GetInstance();
			ICompany company = Company.GetInstance(camp,
				TestBasecamp.GetElementForXml(Properties.Resources.FakeCompany));
			Assert.IsNotNull(company);
			Assert.AreEqual(1776, company.Id);
			Assert.AreEqual("Peter Griffin Brewery", company.Name);
			Assert.AreEqual("123 Main Street", company.Address1);
			Assert.AreEqual("Suite 456", company.Address2);
			Assert.AreEqual("Anytown", company.City);
			Assert.AreEqual("OH", company.State);
			Assert.AreEqual("65445", company.ZipCode);
			Assert.AreEqual("USA", company.Country);
			Assert.AreEqual("http://petergriffinbrewery.example.com", company.WebAddress);
			Assert.AreEqual("343-555-1212", company.PhoneNumberOffice);
			Assert.AreEqual("344-555-1212", company.PhoneNumberFax);
			Assert.AreEqual("PST", company.TimeZoneId);
			Assert.AreEqual(true, company.CanSeePrivate);
		}

		[Test]
		public void GetPeople()
		{
			FakeBaseCamp camp = FakeBaseCamp.GetInstance();
			FakeRestWebService service = FakeRestWebService.GetInstance();
			camp.ServiceGetFakeResult = service;
			ICompany company = Company.GetInstance(camp,
				TestBasecamp.GetElementForXml(Properties.Resources.FakeCompany));
			SetupResponseXml(service, Properties.Resources.FakePeople);
			IPerson[] people = company.People;
			Assert.IsNotNull(people);
			Assert.AreEqual(2, people.Length);
			Assert.AreEqual(TestBasecamp.Person1Id, people[0].Id);
			Assert.AreEqual(TestBasecamp.Person2Id, people[1].Id);
		}

		[Test]
		public void PathForId()
		{
			Assert.AreEqual("companies/1336.xml", Company.PathForId(1336));
		}

		private static void SetupResponseXml(FakeRestWebService service, string xml)
		{
			service.GetRequestResponseElementFakeResult = TestBasecamp.GetElementForXml(xml);
		}
	}
}
